package models

import (
	"time"
)

// Mat: 素材，包括各种形式的资料信息：文章、书籍、章节、诗词、新闻等，这些不同类型的素材都存放在同一张表中，方便进行引用相关的查询
type Mat struct {
	ID      string    `json:"id"`
	AddTime time.Time `json:"addtime"`
	ModTime time.Time `json:"modtime"`
	Kind    MatKind   `json:"kind"`
	Format  MatFormat `json:"format"`
	Title   string    `json:"title"`
	Intro   string    `json:"intro"`
	Content string    `json:"content"`
	Link    string    `json:"link"`
	Source  string    `json:"source"`
	Heat    int       `json:"heat"`
}

type MatForm struct {
	Mat

	Authors    []Person `json:"authors"`
	Pids       string   `json:"pids"`
	Tags       []Tag    `json:"tags"`
	Children   []Mat    `json:"children"`
	IsResource bool     `json:"isresource"`
	Checksum   string   `json:"checksum"`
	Entries    []File   `json:"entries"`
}

type MatSearchForm struct {
	Mypid      string
	Kind       MatKind
	Title      string
	Author     string
	Limit      uint
	Offset     uint
	Orderby    string
	Tag        string
	Random     bool
	Table      MatTable
	Keyword    string
	SearchType SearchType
	Link       string
}

type MatSearchResult struct {
	Total int64     `json:"total"`
	Mats  []MatForm `json:"mats"`
}

type TreeNode struct {
	ID     int64 `json:"id"`
	Parent int64 `json:"parent"`
}

type MatKind int

const (
	KindArticle MatKind = iota
	KindNote
	KindChapter
	KindColl
	KindBook
	KindBookSet
	KindPoem
	KindPoemSet
	KindPin
	KindPinSet
	KindProject
	KindDir
	KindFile
	KindPeople
	KindQuote
)

type MatFormat int

const (
	MatFormatNumber MatFormat = iota
	MatFormatMarkdown
	MatFormatPoem
	MatFormatLink
	MatFormatImage
	MatFormatAudio
	MatFormatVideo
	MatFormatProject
	MatFormatDir
	MatFormatFile
	MatFormatToc
)

type MatScope int

const (
	ScopeChar MatScope = iota
	ScopeWord
	ScopeLine
	ScopePara
	ScopeArticle
	ScopeCollection
)

// Resources

type ProjectImportForm struct {
	URL    string `json:"url"`
	Name   string `json:"name"`
	Source string `json:"source"`
	Desc   string `json:"desc"`
}

type GitTag struct {
	Name string `json:"name"`
	Hash string `json:"hash"`
}

type Version struct {
	Name string `json:"name"`
	Hash string `json:"hash"`
	Desc string `json:"desc"`
}

type File struct {
	Name    string    `json:"name"`
	IsDir   bool      `json:"isdir"`
	Intro   string    `json:"intro"`
	ModTime time.Time `json:"modtime"`
}

type MatTable string

const (
	MatTableMats      = "mats"
	MatTableResources = "resources"
)

type PoemStat struct {
	Fav       int64 `json:"fav"`
	Discover  int64 `json:"discover"`
	Resources int64 `json:"resources"`
}

type SearchType string

const (
	SearchTypeTitle   = "t"
	SearchTypeContent = "c"
	SearchTypeAuthor  = "a"
)
